@extends('layouts.app')

@section('content')
<div class="container">
    <div class="card">
        <div class="card-header d-flex justify-content-between align-items-center">
            <h4 class="mb-0">操作日志</h4>
            <a href="{{ route('operation-logs.export', request()->query()) }}" class="btn btn-success">
                <i class="fas fa-download"></i> 导出日志
            </a>
        </div>

        <div class="card-body">
            <!-- 搜索表单 -->
            <form action="{{ route('operation-logs.index') }}" method="GET" class="mb-4">
                <div class="row g-3">
                    <div class="col-md-3">
                        <input type="text" class="form-control" name="username" 
                               placeholder="用户名" value="{{ request('username') }}">
                    </div>
                    <div class="col-md-3">
                        <input type="text" class="form-control" name="action" 
                               placeholder="操作类型" value="{{ request('action') }}">
                    </div>
                    <div class="col-md-2">
                        <input type="date" class="form-control" name="start_date" 
                               value="{{ request('start_date') }}" placeholder="开始日期">
                    </div>
                    <div class="col-md-2">
                        <input type="date" class="form-control" name="end_date" 
                               value="{{ request('end_date') }}" placeholder="结束日期">
                    </div>
                    <div class="col-md-2">
                        <button type="submit" class="btn btn-primary w-100">搜索</button>
                    </div>
                </div>
            </form>

            <!-- 日志列表 -->
            <div class="table-responsive">
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>用户</th>
                            <th>操作</th>
                            <th>详情</th>
                            <th>IP地址</th>
                            <th>时间</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse($logs as $log)
                            <tr>
                                <td>{{ $log->id }}</td>
                                <td>{{ $log->user ? $log->user->username : '已删除用户' }}</td>
                                <td>{{ $log->action }}</td>
                                <td>{{ $log->content }}</td>
                                <td>{{ $log->ip }}</td>
                                <td>{{ $log->created_at->format('Y-m-d H:i:s') }}</td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="6" class="text-center">暂无操作日志</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>

            <!-- 分页 -->
            <div class="d-flex justify-content-center mt-4">
                {{ $logs->render() }}
            </div>
        </div>
    </div>
</div>
@endsection 